from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response


class DefaultNumberPagination(PageNumberPagination):
    page_size = 5
    page_query_param = 'page'  # 默认页数查询参数名为 page
    page_size_query_param = 'limit'  # 默认页数大小查询参数名为 limit
    max_page_size = 50

    def get_paginated_response(self, data):
        res = {
            'code': 200,
            'message': 'success',
            'data': {
                'total': self.page.paginator.count,
                'result': data,
            }
        }
        return Response(res)
